package poli.tidia.mobile;

import java.util.List;

import poli.tidia.mobile.model.Site;
import poli.tidia.mobile.model.SiteMenuItem;
import poli.tidia.mobile.proxy.SiteCollectionProxy;

import android.app.ListActivity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

public class SitesMenuActivity extends ListActivity  {
	@Override
	public void onCreate (Bundle bundle){
		super.onCreate(bundle);
		
		SiteCollectionProxy scProxy = new SiteCollectionProxy();
		List<SiteMenuItem> sites = scProxy.getMySites();
		setListAdapter(new ArrayAdapter<SiteMenuItem>(this, R.layout.sites_menu, sites));
		
		ListView lv = getListView();
		lv.setBackgroundColor(Color.WHITE);
		lv.setTextFilterEnabled(true);

		lv.setOnItemClickListener(new OnItemClickListener() {
		    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
		    	Site selectedSite = new SiteCollectionProxy().selectSite(((SiteMenuItem)parent.getItemAtPosition(position)).getUrl());

		    	Intent selectedSiteIntent = new Intent(SitesMenuActivity.this, MenuPrincipalActivity.class);

		    	selectedSiteIntent.putExtra("selectedSite", selectedSite);
		    	startActivity(selectedSiteIntent);
		    }
		  });
	}	
}
